﻿/*
Copyright (c) 2008 William Duff

Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all 
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.Text;

namespace LiveUpload.YouTube
{
    /// <summary>
    /// Data related to a specific YouTube user.
    /// </summary>
    internal class Account
    {
        /// <summary>
        /// Constructs a new Account object to represent a YouTube user.
        /// </summary>
        /// <param name="username">
        /// The name of the user.
        /// </param>
        public Account(string name)
        {
            this.name = name;
        }

        /// <summary>
        /// Constructs a new Account object to represent a YouTube user.
        /// </summary>
        /// <param name="username">
        /// The name of the user.
        /// </param>
        /// <param name="token">
        /// An authentication token from YouTube specific to the user.
        /// </param>
        public Account(string name, string token)
        {
            this.name = name;
            this.token = token;
        }

        // Private variables.
        private string name;
        private string token;

        /// <summary>
        /// The name of the user.
        /// </summary>
        public string Name
        {
            get { return this.name; }
        }

        /// <summary>
        /// An authentication token from YouTube specific to the user.
        /// </summary>
        public string Token
        {
            get { return this.token; }
        }

        /// <summary>
        /// This function is used by the ComboBox control to determine the text to be displayed.
        /// </summary>
        /// <returns>
        /// The string to be displayed in the ComboBox.
        /// </returns>
        public override string ToString()
        {
            return this.name;
        }

        /// <summary>
        /// Generic equality function.
        /// </summary>
        /// <param name="obj">
        /// An object to compare equality with.
        /// </param>
        /// <returns>
        /// true if this is equal to the given object and false otherwise.
        /// </returns>
        public override bool Equals(object obj)
        {
            return this == obj as Account;
        }

        /// <summary>
        /// Checks for reference or value equality.
        /// </summary>
        /// <param name="left">
        /// The left hand side of the operator.
        /// </param>
        /// <param name="right">
        /// The right hand side of the operator.
        /// </param>
        /// <returns>
        /// true if the Accounts are equal and false otherwise.
        /// </returns>
        public static bool operator ==(Account left, Account right)
        {
            if (object.ReferenceEquals(left, right))
            {
                return true;
            }
            else if (left is Account && right is Account)
            {
                return left.Name == right.Name;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Checks for reference or value inequality.
        /// </summary>
        /// <param name="left">
        /// The left hand side of the operator.
        /// </param>
        /// <param name="right">
        /// The right hand side of the operator.
        /// </param>
        /// <returns>
        /// true if the Accounts are not equal and false otherwise.
        /// </returns>
        public static bool operator !=(Account left, Account right)
        {
            return !(left == right);
        }

        /// <summary>
        /// Serves as a hash function for Account.
        /// </summary>
        /// <returns>
        /// A hash code.
        /// </returns>
        public override int GetHashCode()
        {
            return this.name.GetHashCode();
        }
    }
}
